package org.goose.web;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;

public class Handler {

	private Method handler;
	private Object parent;
	
	public Handler(Method handler, Object parent){
		this.handler = handler;
		this.parent = parent;
	}
	
	public String invoke(HttpServletRequest request, VelocityContext context, Map pathVariables){
		String t = null;
		try {
			t = (String) handler.invoke(parent, request ,context, pathVariables);
		} catch (IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return t;
	}

	@Override
	public String toString() {
		return "Handler [handler=" + handler + ", parent=" + parent + "]";
	}
}
